home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Reference Guide / C-C++ Interactive Reference Guide.iso / c_ref / csource2 / sclib_1 / 1_2 / v7n2046a.txt < prev    next >
Encoding:
Text File  |  1995-11-01  |  437 b   |  20 lines

  1. #include "malloc.h"
  2. #include <stdio.h>
  3.  
  4. /* This is a program which copies too much data into a
  5.    malloc buffer */
  6.  
  7. main()
  8. {
  9.     char *string1, *string2;
  10.     string1 = malloc(4);
  11.     string2 = malloc(6);
  12.     strcpy(string2, "12345");
  13.     /* about to copy too many characters into string1 */
  14.     strcpy(string1, "ABCDEFGHIJ");
  15.     printf("string1 = >%s<\n", string1);
  16.     printf("string2 = >%s<\n", string2);
  17.     free(string1);
  18.     free(string2);
  19. }
  20.